// 在 common.js 中定义操作 localStorage 的函数
function setSharedData(data) {
    localStorage.setItem('sharedData', JSON.stringify(data));
}

function getSharedData() {
    var storedData = localStorage.getItem('sharedData');
    return storedData ? JSON.parse(storedData) : null;
}

function getSharedDataByIndex(index) {
    debugger
    var storedData = localStorage.getItem('sharedData');
    var item = {}
    if (k in storedData){
        if (storedData[k].item_index == index){
            item = storedData[k]
        }
    }
    return storedData ? JSON.parse(item) : null;
}



function setSharedDataWithExpiry(data, expiryMinutes) {
    var now = new Date();
    var expiryTime = now.getTime() + (expiryMinutes * 60 * 1000); // 转换为毫秒
    // 存储数据和过期时间
    localStorage.setItem('sharedData', JSON.stringify({
        data: data,
        expiryTime: expiryTime
    }));
}

function getSharedDataWithExpiry() {
    var storedData = localStorage.getItem('sharedData');
    if (storedData) {
        var parsedData = JSON.parse(storedData);
        // 检查数据是否过期
        var now = new Date();
        if (now.getTime() < parsedData.expiryTime) {
            return parsedData.data; // 数据未过期，返回
        } else {
            // 数据过期，清除数据
            localStorage.removeItem('sharedData');
        }
    }
    return null; // 没有数据或数据过期，返回null
}


function getURLParameter(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
